package movie.wrapper;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Movie {

	static final String NameTitle = "title";
	static final String URLTitle = "imdburl";
	static final String GenresTitle = "genres";
	static final String RatingTitle = "rating";
	static final String VotesTitle = "votes";
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Long Id;
	
	@Persistent
	public String Name;
	
	@Persistent
	public String URL;
	
	@Persistent
	public String Genres;
	
	@Persistent
	public String Rating;
	
	@Persistent
	public String Votes;
	
	@Persistent
	public String CachedDate;
	
	public Movie(String name, String url, String genres, String rating, String votes)
	{
		Name = name;
		URL = url;
		Genres = genres;
		Rating = rating;
		Votes = votes;
	}
	
	public String GetHTML()
	{
		StringBuilder html = new StringBuilder();
		
		html.append("<table>");
			html.append("<tr>");
				html.append("<td>");
					html.append("Title");
				html.append("</td>");
				html.append("<td>");
					html.append(Name);
				html.append("</td>");
			html.append("</tr>");
			html.append("<tr>");
				html.append("<td>");
					html.append("Genres");
				html.append("</td>");
				html.append("<td>");
					html.append(Genres);
				html.append("</td>");
			html.append("</tr>");
			html.append("<tr>");
				html.append("<td>");
					html.append("Rating");
				html.append("</td>");
				html.append("<td>");
					html.append(Rating);
					html.append("/10 - ");
					html.append(Votes);
					html.append("votes");
				html.append("</td>");
			html.append("</tr>");
			html.append("<tr>");
				html.append("<td>");
					html.append("URL");
				html.append("</td>");
				html.append("<td>");
					html.append("<a href='");
					html.append(URL);
					html.append("' target='_blank'>");
					html.append(URL);
					html.append("</a>");
				html.append("</td>");
			html.append("</tr>");
		html.append("</table>");
		
		return html.toString();
	}
}
